<template>
	<MyPage title="系统权限管理" :isback="true">
		<view slot="gBody">
			<view class="my-content">
				<!--安卓-->
				<view>
				<view  style="border-bottom: #ebebeb solid 1px; padding-bottom: 10px;padding-top: 10px;">
					<view style="width: 15%;float: left;">
						<image src="../../static/images/dt.png" mode="widthFix" style="width: 26px;"></image>
					</view>
					<view style="width: 60%;float: left;">
						<view>位置信息</view>
						<view style="color: #cccccc;margin-top: 10px;font-weight: 300;">我们需要根据你的位置获取所在的地区，用于当前城市的计算器报价。</view>
					</view>
					<view style="width: 25%;float: left;text-align:right;">
						<image v-if="wzqx==1" src="../../static/images/kai.png"  mode="widthFix" style="width: 40px;"></image>
						<image v-if="wzqx==0" src="../../static/images/guan.png"  mode="widthFix" style="width: 40px;"></image>
					</view>
					<view style="clear: both;"></view>
				</view>
						
						
						
				<view style="border-bottom: #ebebeb solid 1px; padding-bottom: 10px;padding-top: 10px;">
					<view style="width: 15%;float: left;">
						<image src="../../static/images/cc.png" mode="widthFix" style="width: 26px;"></image>
					</view>
					<view style="width: 60%;float: left;">
						<view>储存</view>
						<view style="color: #cccccc;margin-top: 10px;font-weight: 300;">发送设备上的招聘、媒体内容和文件等功能</view>
					</view>
					<view style="width: 25%;float: left;text-align:right;">
						<image v-if="ccqx==1" src="../../static/images/kai.png"  mode="widthFix" style="width: 40px;"></image>
						<image v-if="ccqx==0" src="../../static/images/guan.png"  mode="widthFix" style="width: 40px;"></image>
					</view>
					<view style="clear: both;"></view>
				</view>	
					
				<view style="border-bottom: #ebebeb solid 1px; padding-bottom: 10px;padding-top: 10px;">
					<view style="width: 15%;float: left;">
						<image src="../../static/images/xj.png" mode="widthFix" style="width: 26px;"></image>
					</view>
					<view style="width: 60%;float: left;">
						<view>相机</view>
						<view style="color: #cccccc;margin-top: 10px;font-weight: 300;">
							拍摄后发送图片
						</view>
					</view>
					<view style="width: 25%;float: left;text-align:right;">
						<image v-if="xjqx==1" src="../../static/images/kai.png"  mode="widthFix" style="width: 40px;"></image>
						<image v-if="xjqx==0" src="../../static/images/guan.png"  mode="widthFix" style="width: 40px;"></image>
					</view>
					<view style="clear: both;"></view>
				</view>	
				</view>
				<!--//-->
					<view @click="gotoAppPermissionSetting" style="color: #2255DD;text-align: center;margin-top: 20px;">前往系统设置</view>
						 
			</view>
			 
		</view>
	</MyPage>
</template>		

<script>
	import permision from "@/js_sdk/wa-permission/permission.js"
	import uniSegmentedControl from "@/components/uni-segmented-control/uni-segmented-control.vue"
	export default {
		components: {
			uniSegmentedControl
		},
		data() {
			return {
				isIos: true,
				items: ['iOS', 'Android'],
				current: 0,
				wzqx:0,
				ccqx:0,
				xjqx:0
			}
		},
		onLoad() {
		 
			this.isIos = (plus.os.name == "iOS")
			if(this.isIos){
				this.judgeIosPermission('location');
				this.judgeIosPermission('photoLibrary');
				this.judgeIosPermission('camera');
			}else{
				this.requestAndroidPermission('android.permission.ACCESS_FINE_LOCATION');
				this.requestAndroidPermission('android.permission.WRITE_EXTERNAL_STORAGE');
				 this.requestAndroidPermission('android.permission.CAMERA');
				 
			}
		},
		methods: {
			onClickItem(index) {
				if (this.current !== index) {
					this.current = index;
				}
			},
			judgeIosPermission: function(permisionID) {
				var result = permision.judgeIosPermission(permisionID)
				//console.log(result);
				//var strStatus = (result) ? "已" : "未"
				/*uni.showModal({
					content:  strStatus + "获得授权",
					showCancel: false
				});*/
				
				var strStatus = (result) ? 1 : 0;
				
				if(permisionID == 'location'){
					this.wzqx = strStatus;
				}
				if(permisionID == 'photoLibrary'){
					this.ccqx = strStatus;
				}
				if(permisionID == 'camera'){
					this.xjqx = strStatus;
				}
				
			},
			async requestAndroidPermission(permisionID) {
				var result = await permision.requestAndroidPermission(permisionID)
				/*var strStatus
				if (result == 1) {
					strStatus = "已获得授权"
				} else if (result == 0) {
					strStatus = "未获得授权"
				} else {
					strStatus = "被永久拒绝权限"
				} 
				uni.showModal({
					content: strStatus,
					showCancel: false
				});*/
				
				
				var strStatus
				if (result == 1) {
					strStatus = 1
				} else if (result == 0) {
					strStatus = 0
				} else {
					strStatus = 0
				}
				if(permisionID == 'android.permission.ACCESS_FINE_LOCATION'){
					this.wzqx = strStatus;
				}
				if(permisionID == 'android.permission.WRITE_EXTERNAL_STORAGE'){
					this.ccqx = strStatus;
				}
				if(permisionID == 'android.permission.CAMERA'){
					this.xjqx = strStatus;
				}
			},
			gotoAppPermissionSetting: function() {
				permision.gotoAppPermissionSetting()
			},
			checkSystemLocationStatus: function() {
				// var result = permision.checkSystemEnableLocation()
				// console.log(result);
				uni.showModal({
					content: '本机的位置服务开启状态：' + permision.checkSystemEnableLocation(),
					showCancel: false
				});
			},
			gotoAndroidPermissionSetting: function() {
				var main = plus.android.runtimeMainActivity(); //获取activity  
				var Intent = plus.android.importClass('android.content.Intent');
				var Settings = plus.android.importClass('android.provider.Settings');
				var intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS); //可设置http://ask.dcloud.net.cn/question/14732这里所有Action字段
				main.startActivity(intent);
			}
		}
	}
</script> 

<style lang="scss" scoped>
.list-group{
	/deep/ .u-border-top:after{
		border-top:none;
	}
	/deep/ .u-cell{
		padding-left:0;
		padding-right:0;
		.u-cell_title{
			font-size:32rpx;
			color: #333;
		}
	}
}
.btn{
	position:fixed;
	left:5%;
	bottom:50rpx;
	width:90%;
	color: #dd1010 !important;
	border-color: #B00E0E !important;
}
</style>